using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using System.Data.SqlClient;
using System.Data;
namespace DAO
{
    public class KhachHangDAO
    {
        #region TimThongTinKhachHangTheoTen
        public static DataTable TimThongTinKhachHangTheoTen(string TenKH)
        {
            List<SqlParameter> sqlParams = new List<SqlParameter>();
            sqlParams.Add(new SqlParameter("@TenKH", TenKH));
            DataTable dt = SqlDataAccessHelper.ExecuteQuery("spTimThongTinTheoTenKhachHang", sqlParams);
            return dt;
        }
        public static bool KiemTraTimThongTinKhachHangTheoTen(string TenKH)
        {
            bool result = false;
            try
            {
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@TenKH", TenKH));
                DataTable dt = SqlDataAccessHelper.ExecuteQuery("spTimThongTinTheoTenKhachHang", sqlParams);

                if (dt.Rows.Count >= 1)
                {
                    result = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }
        #endregion


        #region TimThongTinKhacHangTheoDiaDiem
        public static DataTable TimThongTinKhacHangTheoDiaDiem(string DiaDiem)
        {
            List<SqlParameter> sqlParams = new List<SqlParameter>();
            sqlParams.Add(new SqlParameter("@TenDiaDiem", DiaDiem));
            DataTable dt = SqlDataAccessHelper.ExecuteQuery("spTimThongTinKhacHangTheoDiaDiem", sqlParams);
            return dt;
        }
        public static bool KiemTraTimThongTinKhacHangTheoDiaDiem(string DiaDiem)
        {
            bool result = false;
            try
            {
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@TenDiaDiem", DiaDiem));
                DataTable dt = SqlDataAccessHelper.ExecuteQuery("spTimThongTinKhacHangTheoDiaDiem", sqlParams);

                if (dt.Rows.Count >= 1)
                {
                    result = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }
        #endregion

        #region TimThongTinKhacHangTheoMaKhachHang
        public static DataTable TimThongTinKhacHangTheoMaKhachHang(string MaKH)
        {
            List<SqlParameter> sqlParams = new List<SqlParameter>();
            sqlParams.Add(new SqlParameter("@MaKH", MaKH));
            DataTable dt = SqlDataAccessHelper.ExecuteQuery("spTimThongTinKhacHangTheoMaKhachHang", sqlParams);
            return dt;
        }
        public static bool KiemTraTimThongTinKhacHangTheoMaKhachHang(string MaKH)
        {
            bool result = false;
            try
            {
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@MaKH", MaKH));
                DataTable dt = SqlDataAccessHelper.ExecuteQuery("spTimThongTinKhacHangTheoMaKhachHang", sqlParams);

                if (dt.Rows.Count >= 1)
                {
                    result = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }
        #endregion

        #region Cap Nhat Thong Tin Khach Hang

        public static bool NhapKhachHang(KhachHangDTO kh)
        {
            bool result = false;
            try
            {
                // Create List Sql Parameter
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@MaKH", kh.MaKH));
                sqlParams.Add(new SqlParameter("@MaDiaDiem", kh.MaDiaDiem));
                sqlParams.Add(new SqlParameter("@SoDienThoai", kh.SoDienThoai));
                // Call Store Procedure
                int n = SqlDataAccessHelper.ExecuteNoneQuery("spInsertKhachHang", sqlParams);
                if (n == 1)
                    result = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }
        public static bool KiemTraNhapKhachHang(String MaKH)
        {
            bool result = false;
            try
            {
                // Create List Sql Parameter
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@MaKH", MaKH));
                DataTable dt = SqlDataAccessHelper.ExecuteQuery("spKiemTraNhapKhachHang", sqlParams);
                if (dt.Rows.Count >= 1)
                {
                    result = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }
        #endregion

        public static DataTable LayThongTinKhachHang(string MaKH)
        {
            List<SqlParameter> sqlParams = new List<SqlParameter>();
            sqlParams.Add(new SqlParameter("@MaKH", MaKH));
            DataTable dt = SqlDataAccessHelper.ExecuteQuery("spLayThongTinKhachHang", sqlParams);
            return dt;
        }
    }
}
